#pragma unmanaged
#include "windows.h"
#include "streams.h"

void RegisterFilter()
{
	 HKEY   hkey;
	 DWORD  dwDisposition; 
	 DWORD	dwType, dwSize;
 
	 if(RegCreateKeyEx(HKEY_CLASSES_ROOT, 
					   TEXT("DShowMediaBridge"), 
					   0, 
					   NULL, 
					   REG_OPTION_NON_VOLATILE, 
					   KEY_ALL_ACCESS, 
					   NULL, 
					   &hkey, 
					   &dwDisposition) == ERROR_SUCCESS)
	 {
		  LPCSTR value = "Source Filter";
		  LPCSTR clsid = "{F7F882ED-485E-431F-A7D9-E6D57E85A59D}";
		  
		  int result = RegSetValueEx(hkey, value, 0, REG_SZ, (BYTE*)clsid, strlen(clsid) + 1);
		  RegCloseKey(hkey);
	 }

	 if(RegCreateKeyEx(HKEY_CURRENT_USER, 
					   TEXT("Software\\Microsoft\\MediaPlayer\\Player\\Schemes\\DShowMediaBridge"), 
					   0, 
					   NULL, 
					   REG_OPTION_NON_VOLATILE, 
					   KEY_ALL_ACCESS, 
					   NULL, 
					   &hkey, 
					   &dwDisposition) == ERROR_SUCCESS)
	 {
		  LPCSTR value = "Runtime";
		  DWORD clsid = 1;
		  
		  int result = RegSetValueEx(hkey, value, 0, REG_DWORD, (BYTE*)&clsid, sizeof(DWORD));
		  RegCloseKey(hkey);
	 }
}

STDAPI DllRegisterServer()
{
	RegisterFilter();
    return AMovieDllRegisterServer2( TRUE );
}

STDAPI DllUnregisterServer()
{
    return AMovieDllRegisterServer2( FALSE );
}

extern "C" BOOL WINAPI DllEntryPoint(HINSTANCE, ULONG, LPVOID);

BOOL WINAPI DllMain(HANDLE hDllHandle, DWORD dwReason, LPVOID lpReserved)
{
   return DllEntryPoint(reinterpret_cast<HINSTANCE>(hDllHandle), dwReason, lpReserved);
}